package service

import (
	"context"
	__ "user-service/basic/proto"
	"user-service/handler/model"
)

// server is used to implement helloworld.GreeterServer.
type Server struct {
	__.UnimplementedUserServer
}

// SayHello implements helloworld.GreeterServer
func (s *Server) Register(_ context.Context, in *__.RegisterReq) (*__.RegisterResp, error) {

	var user model.User
	user = model.User{
		Username: in.Username,
		Password: in.Password,
	}

	if !user.CreateUser() {
		return &__.RegisterResp{
			Code: 400,
			Msg:  "用户创建失败",
		}, nil
	}

	return &__.RegisterResp{
		Code: 200,
		Msg:  "注册成功",
	}, nil
}

func (s *Server) CreateEpisode(_ context.Context, in *__.CreateEpisodeReq) (*__.CreateEpisodeResp, error) {

	var _ model.VideoEpisode
	_ = model.VideoEpisode{
		VideoId: int(in.VideoId),
		Title:   in.Title,
		Desc:    in.Desc,
	}

	return &__.CreateEpisodeResp{
		Code: 200,
		Msg:  "添加成功",
	}, nil
}
